package com.dimples.dd.xxl.job.plus.handler;

import com.dimples.dd.common.result.CommonResult;
import com.dimples.dd.common.result.ResultCode;
import com.dimples.dd.xxl.job.plus.controller.ExecutorController;
import com.xxl.job.core.util.ThrowableUtil;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * RestController 异常处理
 *
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2024/10/18
 */
@ConditionalOnWebApplication
@RestControllerAdvice(basePackageClasses = {ExecutorController.class})
public class XxlJobPlusExceptionHandler {

    /**
     * 服务器内部错误校验
     *
     * @param e 异常
     * @return 处理
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseStatus(HttpStatus.OK)
    public CommonResult<String> exceptionHandler(Exception e) {
        return CommonResult.error(ResultCode.SYSTEM_EXECUTION_ERROR.getCode(), "request error:" + ThrowableUtil.toString(e));
    }
}
